// 存放护士相关的数据
export default {
    //开启命名空间，解决不同模块之间成员冲突的问题
    namespaced: true,
    state: {
        // 护士信息
        nurses: [
            { nurseID: '2001', name: "叶海梅", department: '儿科', title: '护师', phone: '18212001252' },
            { nurseID: '2002', name: "张丽", department: '内科', title: '护士长', phone: '18312004567' },
            { nurseID: '2003', name: "李婷婷", department: '外科', title: '护士', phone: '18412007890' },
            { nurseID: '2004', name: "王红", department: '妇产科', title: '主管护师', phone: '18512002345' },
            { nurseID: '2005', name: "赵静", department: '儿科', title: '护士', phone: '18612006789' },
            { nurseID: '2006', name: "陈艳", department: '内科', title: '护士长', phone: '18712003456' },
            { nurseID: '2007', name: "刘敏", department: '外科', title: '护士', phone: '18812005678' },
            { nurseID: '2008', name: "孙丽", department: '妇产科', title: '主管护师', phone: '18912004680' },
            { nurseID: '2009', name: "李娟", department: '儿科', title: '护士', phone: '17212009012' },
            { nurseID: '2010', name: "周颖", department: '内科', title: '护士长', phone: '17312002468' },
            { nurseID: '2011', name: "吴秀", department: '外科', title: '护士', phone: '17412007901' },
            { nurseID: '2012', name: "朱梅", department: '妇产科', title: '主管护师', phone: '17512003579' },
            { nurseID: '2013', name: "张莉", department: '儿科', title: '护士', phone: '17612005791' },
            { nurseID: '2014', name: "杨娜", department: '内科', title: '护士长', phone: '17712006892' },
            { nurseID: '2015', name: "陈静", department: '外科', title: '护士', phone: '17812008014' },
            { nurseID: '2016', name: "林燕", department: '妇产科', title: '主管护师', phone: '17912004680' },
            { nurseID: '2017', name: "高菲", department: '儿科', title: '护士', phone: '16212009123' },
            { nurseID: '2018', name: "何洁", department: '内科', title: '护士长', phone: '16312003456' },
            { nurseID: '2019', name: "郑丽", department: '外科', title: '护士', phone: '16412007890' },
            { nurseID: '2020', name: "孔佳", department: '妇产科', title: '主管护师', phone: '16512002345' },
            { nurseID: '2021', name: "张三", department: '内科', title: '护士', phone: '16612003456' },
            { nurseID: '2022', name: "李四", department: '儿科', title: '主管护师', phone: '16712004567' },
            { nurseID: '2023', name: "王五", department: '外科', title: '护士', phone: '16812005678' },
            { nurseID: '2024', name: "赵六", department: '妇产科', title: '主管护师', phone: '16912006789' },
            { nurseID: '2025', name: "孙七", department: '内科', title: '护士', phone: '17012007890' },
            { nurseID: '2026', name: "周八", department: '儿科', title: '主管护师', phone: '17112008901' },
            { nurseID: '2027', name: "吴九", department: '外科', title: '护士', phone: '17212009012' },
            { nurseID: '2028', name: "陈十", department: '妇产科', title: '主管护师', phone: '17312000123' },
            { nurseID: '2029', name: "徐一", department: '内科', title: '护士', phone: '17412001234' }
        ],

    },

    getters: {

        //计算护士数量
        getNursesCount(state) {
            return state.nurses.length;
        }

    },

    mutations: {
        // 新增删除护士
        DELETE_NURSE(state, nurseID) {
            const index = state.nurses.findIndex(nurse => nurse.nurseID === nurseID);
            if (index !== -1) {
                state.nurses.splice(index, 1);
            }
        },

        // 添加新护士，
        ADD_NURSE(state, newNurse) {
            state.nurses.unshift(newNurse);
        },

        // 更新护士数据
        UPDATE_NURSE(state, updatedNurse) {
            const index = state.nurses.findIndex(n => n.nurseID === updatedNurse.nurseID);
            if (index !== -1) {
                state.nurses.splice(index, 1, updatedNurse);
            }
        },

        // 关键词过滤
        SET_SEARCH_KEYWORD(state, keyword) {
            state.searchKeyword = keyword; // 保存搜索关键词
            // 进行搜索逻辑，这里直接在mutation中做简单过滤，实际项目中可能需要更复杂的逻辑
            state.filteredNurses = keyword
                ? state.nurses.filter(nurse => nurse.name.includes(keyword))
                : state.nurses; // 如果keyword为空，恢复原始列表
        },
    },

    actions: {

        addNurse({ commit }, newNurse) {
            // 这里可以添加异步操作，如API调用，这里假设直接添加到state简化示例
            commit('ADD_NURSE', newNurse);
            return Promise.resolve();
        },

        updateNurse({ commit }, updatedNurse) {
            // 直接提交 mutation 更新状态，不涉及后端调用
            commit('UPDATE_NURSE', updatedNurse);
        },

        // 搜索护士
        searchNurses({ commit }, keyword) {
            commit('SET_SEARCH_KEYWORD', keyword);
        },

        // 删除护士
        DELETE_NURSE({ commit }, nurseID) {
            commit('DELETE_NURSE', nurseID);
        },
    },
    modules: {

    }
}
